//
//  IconTableViewCell.m
//  阿里星球-音乐界面
//
//  Created by mafeng on 16/8/14.
//  Copyright © 2016年 mafeng. All rights reserved.
//

#import "IconTableViewCell.h"
#import "iconCollectionViewCell.h"

@interface IconTableViewCell () <UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@property (nonatomic, strong) NSArray<twodatamodel *> *dataArray;
@end
@implementation IconTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    
    
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        self.layout = [[UICollectionViewFlowLayout alloc] init];
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:_layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        [_collectionView registerNib:[UINib nibWithNibName:NSStringFromClass([iconCollectionViewCell class]) bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"iconReuse"];
        [self.contentView addSubview:_collectionView];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _collectionView.frame = self.bounds;
    _layout.itemSize = CGSizeMake((self.bounds.size.width - 20) / 3, self.bounds.size.height);
    _layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    _layout.minimumLineSpacing = 5;
    _layout.sectionInset = UIEdgeInsetsMake(0, 5, 0, 5);
}

// collectionView的协议方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 3;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    iconCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"iconReuse" forIndexPath:indexPath];
    cell.smallData = _dataArray[indexPath.row];
    return cell;
}
- (void)setData:(dataModel *)data {
    NSLog(@"🐷%@", _data.data);
    _data = data;
    _dataArray = [NSArray array];
    _dataArray = data.data;
    [_collectionView reloadData];
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
